package com.habdqn.easybuy.web.manage.product;

import com.habdqn.easybuy.entity.Product;
import com.habdqn.easybuy.service.ProductService;
import com.habdqn.easybuy.service.impl.ProductServiceImpl;
import com.habdqn.easybuy.util.Page;
import com.habdqn.easybuy.util.StringUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author Xing.Jiejian
 * @date 2020/11/26 0026
 */
@WebServlet(name = "ProductListServlet", urlPatterns = "/manage/product")
public class ListServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Page<Product> page = new Page<>();
        String strPageNo = request.getParameter("pageNo");
        if (StringUtils.isNotBlank(strPageNo)) {
            page.setPageNo(Integer.parseInt(strPageNo));
        }
        String strPageSize = request.getParameter("pageSize");
        if (StringUtils.isNotBlank(strPageSize)) {
            page.setPageSize(Integer.parseInt(strPageSize));
        }

        ProductService productService = new ProductServiceImpl();
        productService.queryByPage(null, page,true);

        request.setAttribute("page", page);
        request.getRequestDispatcher("/WEB-INF/manage/product/product.jsp").forward(request, response);
    }
}
